package tk.zater.Util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Iterator;
import java.util.Set;

import org.apache.log4j.Logger;

import tk.zater.CS.EsetVersionConfigeration;
import tk.zater.CS.FileName;
import tk.zater.CS.UserAccountManagermant;

public class fileinfoutil {
	EsetVersionConfigeration evc;
	Logger logger = Logger.getLogger(VerGenerator.class);
	
	
    public fileinfoutil(EsetVersionConfigeration evc) {
		super();
		this.evc = evc;
		saveFile=new File(evc.absolutePath + "/file.zater");;
	}

	public File saveFile ;
			
		

    public void readfile() {
        ObjectInputStream in;
        try {
        	if(!saveFile.exists()){return;}
            in = new ObjectInputStream(new FileInputStream(saveFile));
            int size = in.readInt();
            for (int i = 0; i < size; i++) {
                FileName temp=(FileName) in.readObject();
                evc.nowlist.nowlist.put(temp.filename,temp);
            }
            System.out.println(evc.nowlist.nowlist);
        } catch (IOException e) {
        	 logger.error(e.getStackTrace());
        } catch (ClassNotFoundException ex) {
       logger.error("error1015:classException");
        }

    }

   

	public void writefile() {
        ObjectOutputStream out = null;
        int size =evc. nowlist.nowlist.size();
        try {
            out = new ObjectOutputStream(new FileOutputStream(saveFile));
            out.writeInt(size);
            Set<String> list = evc.nowlist.nowlist.keySet();
            Iterator<String> it = list.iterator();
            while (it.hasNext()) {
                String nextname=it.next();
                FileName nextFileName=evc.nowlist.nowlist.get(nextname);
               // System.out.println(nextFileName);
                out.writeObject(nextFileName);
            }
             out.close();
        } catch (IOException ex) {
            logger.error("Error 1014:output error.输出错误");
        }
       

    }
}
